import RedisUtils from '../../utils/RedisUtils'

export const info = (doc, db, callback) => {
  RedisUtils.getRedisConnect(doc, db, (client) => {
    // eslint-disable-next-line handle-callback-err
    return client.info((err, result) => {
      let split = result.split('\n')
      let data = []
      for (const splitElement of split) {
        if (splitElement.search('#') === -1) {
          let strings = splitElement.split(':')
          data.push({
            name: strings[0],
            value: strings[1]
          })
        }
      }
      callback(data)
    })
  })
}

export const isCluster = (doc, db, callback) => {
  RedisUtils.getRedisConnect(doc, db, (client) => {
    // eslint-disable-next-line handle-callback-err
    return client.info((err, result) => {
      let indexOf = result.indexOf('redis_mode')
      let substring = result.substring(indexOf + 11, indexOf + 18)
      // eslint-disable-next-line standard/no-callback-literal
      callback(substring === 'cluster')
    })
  })
}
